
import re
import matplotlib.pyplot as plt
import numpy as np

FILE = 'build/refline.txt'

with open(FILE, 'r') as fd:
    data = fd.readlines()

def to_sl(sl_str):
    s, l = sl_str.split(',')
    return float(s), float(l)

fig, ax = plt.subplots(figsize=(20, 5))

max_x = -float('inf')
min_x = float('inf')
max_y = -float('inf')
min_y = float('inf')

print(f'data len: {len(data)}')
for line in data:
    result = re.findall(r'\((.*?)\)', line) 
    x_list = []
    y_list = []

    for point_index, sl_str in enumerate(result):
        s, l = to_sl(sl_str)
        x_list.append(s)
        y_list.append(l)

    max_x = max(max(x_list), max_x)
    max_y = max(max(y_list), max_y)
    min_x = min(min(x_list), min_x)
    min_y = min(min(y_list), min_y)
    # print(f'x_list len: {len(x_list)}')

    ax.plot(x_list, y_list, linestyle='-')

print(f'max_x: {max_x}, max_y: {max_y}, min_x: {min_x}, min_y: {min_y}')
ax.set_aspect(1.0)
ax.grid(True, which='both', linestyle='--', linewidth=0.5)
ax.set_xticks(np.arange(min_x, max_x, 10.0))  # x轴刻度步长0.5
ax.set_yticks(np.arange(min_y, max_y, 10.0))  # y轴刻度步长0.5
 
plt.show()